import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public class UserManager {
    private final List<User> users;
    private static final Pattern PASSWORD_PATTERN = Pattern.compile("^.{5,}$");

    public UserManager() {
        this.users = new ArrayList<>();// 初始化用户列表
    }

    public boolean register(String username, String password) {
        if (!PASSWORD_PATTERN.matcher(password).matches()) {
            return false; // 密码长度不足
        }
        for (User user : users) {
            if (user.getUsername().equals(username)) {
                return false; // 用户名已存在
            }
        }
        users.add(new User(username, password));
        return true;// 注册成功
    }

    public boolean login(String username, String password) {
        for (User user : users) {
            if (user.getUsername().equals(username) && user.getPassword().equals(password)) {
                return true;
            }
        }
        return false;
    }
}